//
//  HYGetMainCompanyListApi.m
//  TJHYHardwareProduct
//
//  Created by JianWei Chen on 2018/1/23.
//  Copyright © 2018年 Kendama. All rights reserved.
//

#import "HYGetMainCompanyListApi.h"

@implementation HYGetMainCompanyListApi{
    NSDictionary *_dic;
}

-(id)initWithDic:(NSDictionary *)dic{
    if (self = [super init]) {
        _dic = dic;
    }
    return self;
}

- (NSString *)requestUrl {
    return @"/company/get_list";
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPOST;
}

- (id)requestArgument {
    NSMutableDictionary *dic = [NSMutableDictionary getPubdic];
    
    [dic setValuesForKeysWithDictionary:_dic];
    NSString *sign=[NSString getSign:dic];
    [dic setObject:sign forKey:@"sign"];
    return dic;
}


-(void)dealloc
{
    NSLog(@"%@ dealloc",[self class]);
}

+ (void)getCompanyMainList:(void (^)(NSArray<HYMainCompanyModel *> *))successBack fail:(void (^)(NSDictionary *))failBack
{
    NSMutableDictionary *requestDic = [[NSMutableDictionary alloc]init];
    
    HYGetMainCompanyListApi *api = [[HYGetMainCompanyListApi alloc]initWithDic:requestDic];
    [api dtStartYTKRequestCompletionBlockWithSuccess:^(YTKBaseRequest * _Nonnull request) {
        NSMutableArray *mainList = [[NSMutableArray alloc]init];
        NSDictionary *dic = request.responseObject;
        if (dic[@"data"] && [dic[@"data"] isKindOfClass:[NSArray class]]) {
            NSArray *list = dic[@"data"];
            for (NSDictionary *infoDic in list) {
                HYMainCompanyModel *model = [[HYMainCompanyModel alloc]init];
                [model setValuesForKeysWithDictionary:infoDic];
                [mainList addObject:model];
            }
        }
        if (successBack) {
            successBack(mainList);
        }
    } failure:^(YTKBaseRequest * _Nonnull request) {
        if (failBack) {
            failBack(request.responseObject);
        }
    }];
}

+ (void)getCompanyMainListProvince:(NSString *)province city:(NSString *)city district:(NSString *)district success:(void (^)(NSArray<HYMainCompanyModel *> *list))successBack fail:(void (^)(NSDictionary *dic))failBack
{
    NSMutableDictionary *requestDic = [[NSMutableDictionary alloc]init];
    [requestDic setValue:province forKey:@"province"];
    [requestDic setValue:city forKey:@"city"];
    [requestDic setValue:district forKey:@"district"];
    
    HYGetMainCompanyListApi *api = [[HYGetMainCompanyListApi alloc]initWithDic:requestDic];
    [api dtStartYTKRequestCompletionBlockWithSuccess:^(YTKBaseRequest * _Nonnull request) {
        NSMutableArray *mainList = [[NSMutableArray alloc]init];
        NSDictionary *dic = request.responseObject;
        if (dic[@"data"] && [dic[@"data"] isKindOfClass:[NSArray class]]) {
            NSArray *list = dic[@"data"];
            for (NSDictionary *infoDic in list) {
                HYMainCompanyModel *model = [[HYMainCompanyModel alloc]init];
                [model setValuesForKeysWithDictionary:infoDic];
                [mainList addObject:model];
            }
        }
        if (successBack) {
            successBack(mainList);
        }
    } failure:^(YTKBaseRequest * _Nonnull request) {
        if (failBack) {
            failBack(request.responseObject);
        }
    }];
}
@end
